package com.example.exam;


import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class ExamActivity extends Activity {

    public static final String EXTRA_MESSAGE = "ExamId";
    int ExamId;

    public String id;
    public String lesson;
    public String chapter;
    public String difficulty;
    public String title;
    public String option_a;
    public String option_b;
    public String option_c;
    public String option_d;
    public String information_1;
    public String information_2;

    public TextView information_1_text;
    public TextView information_2_text;
    public TextView title_text;
    public RadioButton option_a_text;
    public RadioButton option_b_text;
    public RadioButton option_c_text;
    public RadioButton option_d_text;
    Button last_button;
    Button next_button;
    RadioGroup rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exam);
        Intent intent = getIntent();
        ExamId =  Integer.parseInt(intent.getStringExtra(EXTRA_MESSAGE));

        rg = findViewById(R.id.radioGroup);
        information_1_text = findViewById(R.id.information_1);
        information_2_text = findViewById(R.id.information_2);
        title_text = findViewById(R.id.exam_title);
        option_a_text = findViewById(R.id.btn_a);
        option_b_text = findViewById(R.id.btn_b);
        option_c_text = findViewById(R.id.btn_c);
        option_d_text = findViewById(R.id.btn_d);
        last_button = findViewById(R.id.last_title);
        next_button = findViewById(R.id.next_title);

        setExam(ExamId);

        last_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(ExamId != 0){
                    rg.clearCheck();
                    ExamId--;
                    setExam(ExamId);
                }
                else return;
            }
        });
        next_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rg.clearCheck();
                if(ExamId < Questions.QuestionsList.size() - 1) ExamId++;
                setExam(ExamId);
            }
        });
    }

    void setExam(int ExamId){
        id = "编号:" + Questions.QuestionsList.get(ExamId).getId();
        lesson = "课程名:" + Questions.QuestionsList.get(ExamId).getLesson();
        information_1 = id + "  " + lesson;
        chapter = "章节:" + Questions.QuestionsList.get(ExamId).getChapter();
        difficulty = "难度:" + Questions.QuestionsList.get(ExamId).getDifficulty();
        information_2 = chapter + "  " + difficulty;
        title = "题目:" + Questions.QuestionsList.get(ExamId).getTitle();
        option_a = "A. " + Questions.QuestionsList.get(ExamId).getOption_a();
        option_b = "B. " + Questions.QuestionsList.get(ExamId).getOption_b();
        option_c = "C. " + Questions.QuestionsList.get(ExamId).getOption_c();
        option_d = "D. " + Questions.QuestionsList.get(ExamId).getOption_d();

        information_1_text.setText(information_1);
        information_2_text.setText(information_2);
        title_text.setText(title);
        option_a_text.setText(option_a);
        option_b_text.setText(option_b);
        option_c_text.setText(option_c);
        option_d_text.setText(option_d);
    }
}
